﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using PServiceBus.Core.Interface;
using Phoenix.ReflectionExtensions;
using PServiceBus.Core.Runtime;
using PServiceBus.Core.Logger;

namespace PServiceBus.Core.Configuration {
    internal class TopicMessageEnricherElement : ConfigurationElement, PServiceBus.Core.Interface.ITopicMessageEnricherConfig {
        public TopicMessageEnricherElement() { }
        public TopicMessageEnricherElement(string name) { Name = name; }
        [ConfigurationProperty("name", IsRequired = true, IsKey = true)]
        public string Name {
            get { return base["name"] as string; }
            set { base["name"] = value; }
        }
        [ConfigurationProperty("type", IsRequired = true)]
        public string Type {
            get { return base["type"] as string; }
            set { base["type"] = value; }
        }
    }
    [ConfigurationCollection(typeof(TopicMessageEnricherElement), CollectionType = ConfigurationElementCollectionType.BasicMap)]
    internal sealed class TopicMessageEnricherCollection : ConfigurationElementCollection {
        protected override ConfigurationElement CreateNewElement() {
            return new TopicMessageEnricherElement();
        }

        protected override object GetElementKey(ConfigurationElement element) {
            return (element as TopicMessageEnricherElement).Name;
        }
    }
    public sealed class TopicMessageEnricherConfigSection : ConfigurationSection {
        [ConfigurationProperty("enrichers", IsDefaultCollection = true, IsRequired = true)]
        internal TopicMessageEnricherCollection Enrichers {
            get { return this["enrichers"] as TopicMessageEnricherCollection; }
        }
    }
}
